setwd("c:/test/Cousera/")

corr <- function(directory, threshold = 0) {
  filename <- list.files(directory, full.names=TRUE)
  ts <- numeric()
  for (x in filename) {
    tdata <- read.csv(x, header = TRUE)
    sumcases <- sum(complete.cases(tdata))
    if (sumcases > threshold) {
      tdatatemp <- subset(tdata, complete.cases(tdata) == "TRUE")
      cortemp <- cor(tdatatemp$sulfate, tdatatemp$nitrate)
      ts <- c(ts, cortemp)
    }
  }
  ts
}

cr <- corr("specdata", 150)
head(cr)